clear all
set more off
cd "/Users/yasenov/Dropbox (IPL)/RefugeeBan/Data/CityMapping/Census_County_Files"

capture log close
log using "../../logs/county_dict", replace

*********
*********
*********

import delimited "national_county.txt"

rename (v1 v2 v3 v4) (state_abbr state_fips county_fips county)
drop v5
drop if state_fips > 56
replace county = substr(county, 1, strlen(county) - 7)
replace county = trim(county)

replace state_abbr = trim(state_abbr)
compress

merge m:1 state_abbr using "state_dictionary.dta", nogen keepusing(state)
order state state_abbr state_fips county county_fips, first
sort state_fips county_fips

tostring state_fips county_fips, replace
replace state_fips = "0" + state_fips if strlen(state_fips) == 1
replace county_fips = "0" + county_fips if strlen(county_fips) == 2
replace county_fips = "00" + county_fips if strlen(county_fips) == 1

gen fips = state_fips + county_fips
isid fips

desc
sum
list in 1/10
qui compress

save "county_dict.dta", replace

capture log close
